<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
    >
      <el-form-item label="提现账单编号" prop="businesscode">
        <el-input
          v-model="queryParams.businesscode"
          placeholder="请输入"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申请时间" prop="starttime">
        <el-date-picker
          v-model="queryParams.starttime"
          type="date"
          placeholder="选择日期"
        >
        </el-date-picker>
        <span> - </span>
        <el-date-picker
          v-model="queryParams.endtimes"
          type="date"
          placeholder="选择日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-button type="primary" size="small" @click="handleedit('add')"
        >新增</el-button
      >
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table ref="multipleTable" v-loading="loading" :data="supplierList">
      <el-table-column label="序号" align="center" prop="id" width="100">
        <template slot-scope="scope">
          <div>
            {{
              scope.$index +
              (queryParams.pageNum - 1) * queryParams.pageSize +
              1
            }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="提现账单编号"
        align="center"
        prop="businesscode"
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <div>{{ scope.row.supplierName }}</div>
        </template>
      </el-table-column>
      <el-table-column
        label="业务部名称"
        align="center"
        prop="businessName"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        label="申请提现金额(￥)"
        align="center"
        prop="withdrawal"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        label="手续费(￥)"
        align="center"
        prop="ServiceCharge"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        label="实际到账金额(￥)"
        align="center"
        prop="arrival"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        label="申请提现日期"
        align="center"
        prop="updateTime"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
       <el-table-column
        label="银行账号"
        align="center"
        prop="bankaccount"
      >
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        prop="opration"
        width="200"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            type="text"
            size="mini"
            @click="handleedit('edit', scope.row)"
            >审核</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加或修改公告对话框 -->
    <el-dialog
      :title="title"
      :visible="open"
      width="780px"
      append-to-body
      :before-close="handeclose"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="11">
            <el-form-item
              label="垫资方名称:"
              prop="supplierName"
              v-if="!issupplier"
            >
              <el-input
                v-model="form.supplierName"
                :disabled="isdisable"
                placeholder="请输入"
              />
            </el-form-item>
            <el-form-item
              label="提现账单编号:"
              prop="supplierName"
              v-if="issupplier"
            >
              <el-input
                v-model="form.supplierName"
                :disabled="isdisable"
                placeholder="请输入"
              />
            </el-form-item>
            <el-form-item label="所在地址:" prop="address">
              <el-input
                v-model="form.address"
                :disabled="isdisable"
                placeholder="请输入"
              />
            </el-form-item>
            <el-form-item label="收款商户号:" prop="payEemerchantNo">
              <el-select
                v-model="form.payEemerchantNo"
                :disabled="isdisabletwo"
                placeholder="请选择"
                style="width: 100%"
              >
                <el-option
                  v-for="item in payEemerchantNooptions"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item
              label="平台手续费:"
              prop="platformfee"
              v-if="issupplier"
            >
              <el-input
                v-model="form.platformfee"
                :disabled="isdisable"
                placeholder="请输入"
              />
            </el-form-item>
            <el-form-item
              :label="'银行名称:\n(BankName)'"
              prop="bankName"
              class="formdata"
            >
              <el-input
                v-model="form.bankName"
                :disabled="isdisable"
                placeholder="请输入"
              />
            </el-form-item>
            <el-form-item
              :label="'银行账号:\n(BankAccount)'"
              prop="bankAccount"
              class="formdata"
            >
              <el-input
                v-model="form.bankAccount"
                :disabled="isdisable"
                placeholder="请输入"
              />
            </el-form-item>
            <el-form-item
              :label="'Swift代码:\n(SwiftCode)'"
              prop="swiftCode"
              class="formdata"
            >
              <el-input
                v-model="form.swiftCode"
                :disabled="isdisable"
                placeholder="请输入"
              />
            </el-form-item>
          </el-col>
          <el-col :span="11" :offset="1">
            <el-form-item label="所在国家" prop="nation">
              <el-select
                v-model="form.nation"
                :disabled="isdisable"
                placeholder="请选择"
                style="width: 100%"
              >
                <el-option
                  v-for="item in nationoptions"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="供应商类别:" prop="category" v-if="issupplier">
              <el-select
                v-model="form.category"
                :disabled="isdisabletwo"
                placeholder="请选择"
                style="width: 100%"
              >
                <el-option
                  v-for="item in categoryoptions"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="负责人:" prop="userName">
              <el-input
                v-model="form.userName"
                :disabled="isdisable"
                placeholder="请输入"
              />
            </el-form-item>
            <el-form-item label="手机号:" prop="phone">
              <el-input
                v-model="form.phone"
                :disabled="isdisable"
                placeholder="请输入"
              />
            </el-form-item>
            <el-form-item
              :label="'账户名称:\n(AccountName)'"
              prop="accountName"
              class="formdata"
            >
              <el-input
                v-model="form.accountName"
                :disabled="isdisable"
                placeholder="请输入"
              />
            </el-form-item>
            <el-form-item
              :label="'IBAN代码:\n(IBANCode)'"
              prop="IBANCode"
              class="formdata"
            >
              <el-input
                v-model="form.IBANCode"
                :disabled="isdisable"
                placeholder="请输入"
              />
            </el-form-item>
            <el-form-item
              :label="'支行代码:\n(BranchCode)'"
              prop="branchCode"
              class="formdata"
            >
              <el-input
                v-model="form.branchCode"
                :disabled="isdisable"
                placeholder="请输入"
              />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item
              :label="'银行地址:\n(BankAddress)'"
              prop="bankAddress"
              class="formdata"
            >
              <el-input
                v-model="form.bankAddress"
                :disabled="isdisable"
                placeholder="请输入"
              />
            </el-form-item>
            <el-form-item label="启用状态" prop="state">
              <el-radio v-model="form.state" label="1">已启用</el-radio>
              <el-radio v-model="form.state" label="2">已禁用</el-radio>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listsupplier,
  addsupplier,
  editsupplier,
  delsupplier,
} from "@/api/supplier";
import Editor from "@/components/Editor";
import selfDirective from "@/utils/selfDirective";
import FileUpload from "@/components/FileUpload/index";

export default {
  name: "supplier",
  components: {
    Editor,
    FileUpload,
  },
  data() {
    var checkPhone = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("手机号不能为空"));
      } else {
        const reg = /^1[3|4|5|7|8][0-9]\d{8}$/;
        if (reg.test(value)) {
          callback();
        } else {
          return callback(new Error("请输入正确的手机号"));
        }
      }
    };
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 公告表格数据
      supplierList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 状态数据字典
      typeOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {
        icon: [],
        sort: null,
        name: "",
      },
      // 表单校验
      rules: {
        supplierName: [
          {
            required: true,
            message: "提现账单编号不能为空",
            trigger: "change",
          },
        ],
        nation: [
          {
            required: true,
            message: "供应商所在国家不能为空",
            trigger: "change",
          },
        ],
        address: [
          {
            required: true,
            message: "所在地址不能为空",
            trigger: "change",
          },
        ],
        payEemerchantNo: [
          {
            required: true,
            message: "收款商户号不能为空",
            trigger: "change",
          },
        ],
        platformfee: [
          {
            required: true,
            message: "平台手续费不能为空",
            trigger: "change",
          },
        ],
        bankName: [
          {
            required: true,
            message: "银行名称不能为空",
            trigger: "change",
          },
        ],
        bankAccount: [
          {
            required: true,
            message: "银行账号不能为空",
            trigger: "change",
          },
        ],
        swiftCode: [
          {
            required: true,
            message: "Swift代码不能为空",
            trigger: "change",
          },
        ],
        district: [
          { required: true, message: "供应商地区不能为空", trigger: "change" },
        ],
        userName: [
          {
            required: true,
            message: "供应商负责人不能为空",
            trigger: "change",
          },
        ],
        phone: [
          {
            required: true,
            trigger: "change",
            validator: checkPhone,
          },
        ],
        category: [
          { required: true, message: "供应商类别不能为空", trigger: "change" },
        ],
        company: [
          { required: true, message: "代收款公司不能为空", trigger: "change" },
        ],
        state: [
          { required: true, message: "请选择是否启用", trigger: "change" },
        ],
      },
      issupplier: true,
      limit: 5,
      fileSize: 20,
      isShowTip: false,
      value: [],
      nationoptions: [],
      categoryoptions: [],
      companyoptions: [],
      gysTypeOptions: [],
      payEemerchantNooptions: [],
      isdisable: false,
      isdisabletwo: false,
      statusoptions: [
        {
          dictValue: "1",
          dictLabel: "已启用",
        },
        {
          dictValue: "2",
          dictLabel: "已禁用",
        },
      ],
    };
  },
  created() {
    if (this.$route.params[1]) {
      this.issupplier = false;
    } else {
      this.issupplier = true;
    }
    this.getList();
    this.getDicts("gys_type").then((response) => {
      this.categoryoptions = response.data;
    });
    this.getDicts("gys-gj").then((response) => {
      this.nationoptions = response.data;
    });
    this.getDicts("pay-eemer-chantNo").then((response) => {
      this.payEemerchantNooptions = response.data;
    });
  },
  methods: {
    /** 查询公告列表 */
    handelcopy() {
      copysupplier().then((res) => {
        this.msgSuccess("复制成功");
      });
    },
    /** 查询公告列表 */
    changeStatus(value) {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 查询公告列表 */
    getList() {
      this.loading = true;
      listsupplier(this.queryParams).then((response) => {
        var supplierList = response.rows||[];
        this.supplierList = supplierList;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 公告状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 公告状态字典翻译
    typeFormat(row, column) {
      return this.selectDictLabel(this.typeOptions, row.noticeType);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        state: "1",
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != undefined) {
            editsupplier(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addsupplier(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    handleedit(type, row) {
      this.reset();
      this.open = true;
      if (type == "edit") {
        this.form = row;
        this.title = "修改标签";
        this.isdisable = false;
        this.isdisabletwo = true;
      } else if (type == "add") {
        this.title = "新增标签";
        this.isdisable = false;
      } else if (type == "more") {
        this.form = row;
        this.isdisable = true;
        this.isdisabletwo = true;
      }
    },
    handeclose() {
      this.open = false;
    },
    getdictlabel(row, nationoptions, name) {
      let str = "";
      nationoptions.map((item) => {
        if (item.dictValue == row[name]) {
          str = item.dictLabel;
        }
      });
      return str;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm("是否确认删除该仓库?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return delsupplier(ids);
        })
        .then(() => {
          this.getList();
          this.$message.success("删除成功");
        })
        .catch(() => {});
    },
    changestate(row) {
      var that = this;
      const statestr = row.state == 1 ? "禁用" : "启用";
      this.$confirm("是否确认" + statestr + "该供应商?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(function () {
        var obj = {
          id: row.id,
          state: row.state == 1 ? 0 : 1,
        };
        editsupplier(obj).then((response) => {
          that.$message.success(statestr + "成功");
          that.getList();
        });
      });
    },
  },
};
</script>
<style scoped lang="scss">
.radio-box {
  margin-bottom: 10px;
}
.stock {
  text-decoration: underline;
}
.copy {
  color: #999;
  cursor: pointer;
}
.box-card {
  margin-top: 20px;
  .card-title {
    font-weight: 700;
    font-style: normal;
    color: #555555;
  }
  .baseinfo {
    width: 100%;
    height: 40px;
    line-height: 40px;
    color: #999;
    background-color: #f2f2f2;
    padding-left: 10px;
    border-radius: 5px;
    margin-top: 10px;
  }
}
.dialog-footer {
  display: flex;
  justify-content: center;
  align-items: center;
}
::v-deep {
  .el-table .cell {
    white-space: pre-line !important; /*保留换行符*/
  }

  .el-form-item__content {
    line-height: 30px;
  }
  .el-upload--picture-card {
    width: 50px;
    height: 50px;
    line-height: 58px;
  }
}
.formdata ::v-deep {
  .el-form-item__label {
    white-space: pre-line !important; /*保留换行符*/
    line-height: 15px;
  }
}
</style>